let getImageCache = (key, url) => {
  return new Promise((resolve, reject) => {
    const path = wx.getStorageSync(key)
    if (path) {
      resolve(path)
    } else {
      wx.cloud.downloadFile({
        fileID: url,
        success: function (res) {
          if (res.statusCode === 200) {
            // console.log ( '图片下载成功')
            const fs = wx.getFileSystemManager()
            fs.saveFile({
              tempFilePath: res.tempFilePath,
              success(res) {
                // console.log ( '图片缓存成功')
                wx.setStorageSync(key, res.savedFilePath)
                resolve(res.savedFilePath)
              }
            })
          } else {
            reject(res.statusCode)
          }
        }
      })
    }
  })

}



module.exports = {
  getImageCache
}